package com.mes.schedule.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * by lqm
 * 可并行的多能力设备MultiCapacity，如毛刺台
 */

public class McDevice extends SDevice implements Serializable {

	protected List<SDevice> virtualDeviceList=new ArrayList<SDevice>();

	public List<SDevice> getVirtualDeviceList() {
		return virtualDeviceList;
	}

	public McDevice() {
		super();
	}

	public void setVirtualDeviceList(List<SDevice> virtualDeviceList) {
		this.virtualDeviceList = virtualDeviceList;
	}

	// 构造多能力虚拟设备
	public void generateVirtualDevice() {
		

		for (int i = 0; i < resCapacity; i++) {
			SDevice vd = new SDevice();
			vd.setDeviceUid(this.deviceUid + "-" + (i + 1));
			vd.setDeviceName(this.deviceName + "-" + (i + 1));
			vd.setResUid(vd.getDeviceUid());
			vd.setResName(vd.getDeviceName());
			vd.setResCapacity(1);
			vd.setScheme(this.scheme);


			vd.setCalendar(this.calendar);
			vd.setCalendarUid(this.calendarUid);
			vd.setDeviceClass(this.deviceClass);
			vd.setDeviceClassName(this.deviceClassName);
			vd.setCriticalLevel(this.criticalLevel);
			vd.setResType(this.resType);
			vd.setVirtual(true);
			this.scheme.deviceMap.put(vd.getDeviceUid(), vd);
			virtualDeviceList.add(vd);

		}

	}

	@Override
	public void setCalendar(SCalendar calendar) {
		if (virtualDeviceList != null && virtualDeviceList.size() > 0) {
			for (SDevice v : this.virtualDeviceList) {
				v.setCalendar(calendar);
			}

		}
		super.setCalendar(calendar);
	}

	@Override
	public void setCalendarUid(String calendarUid) {
		if (virtualDeviceList != null && virtualDeviceList.size() > 0) {
			for (SDevice v : virtualDeviceList) {
				v.setCalendarUid(calendarUid);
			}
		}

		super.setCalendarUid(calendarUid);
	}

	public McDevice(int resCapacity) {
		super();

		this.resCapacity = resCapacity;
	}

	
	//多能力设备，与无限能力设备部能用序列
	public boolean canUseSeq()
	{

		return false;
		
	}

	
	@Override
	public void setCalIgnoreCapacityBoolean(boolean calIgnoreCapacityBoolean) {
		// TODO Auto-generated method stub
		if (virtualDeviceList != null && virtualDeviceList.size() > 0) {
			for (SDevice v : virtualDeviceList) {
				v.setCalIgnoreCapacityBoolean(calIgnoreCapacityBoolean);
			}
		}
		super.setCalIgnoreCapacityBoolean(calIgnoreCapacityBoolean);
	}
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		try {
			super.destroy();
			if(this.virtualDeviceList!=null)
			{
				this.virtualDeviceList.clear();
				this.virtualDeviceList=null;
			}
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	

	@Override
	public int getCalDeviceCurrentSegment() {
		// TODO Auto-generated method stub
		if (virtualDeviceList != null && virtualDeviceList.size() > 0) {
			int tmp=Integer.MAX_VALUE;
			for (SDevice v : virtualDeviceList) {
				if(v.getCalDeviceCurrentSegment()<tmp)
					tmp=v.getCalDeviceCurrentSegment();
			}
			return tmp;
		}
		return super.getCalDeviceCurrentSegment();
	}
	
	
}
